'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 副本
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var dataApi = require('../libs/dataApi');

/**
 * 获取副本随机奖励配置
 * @param  {[type]} copy_id [description]
 * @return {[type]}            [description]
 */
exports.getCarbonRandomRewardConf = function (job_type, copy_id) {
    var copy_reward_id = job_type * 100000 + copy_id;
    return dataApi.carbon_random_reward.findById(copy_reward_id);
};

exports.getCarbonFixRewardConf = function (job_type, copy_id) {
    var copy_reward_id = job_type * 100000 + copy_id;
    return dataApi.carbon_set_reward.findById(copy_reward_id);
};

exports.getCarbonFirstRewardConf = function (job_type, copy_id) {
    var copy_reward_id = job_type * 100000 + copy_id;
    return dataApi.carbon_first_reward.findById(copy_reward_id);
};

/**
 * 获取副本星星配置
 * @param  {[type]} build_type [description]
 * @return {[type]}            [description]
 */
exports.getCopyStarConf = function (main_copy_id, box_position) {
    var star_conf = {};
    var position = box_position - 1;
    dataApi.star_reward.any(function (star_item, key) {
        if (key == main_copy_id) {
            star_conf = star_item[position];
            return true;
        }
    });
    return star_conf;
};

/**
 * 获取副本建筑的配置
 * @param  {[type]} build_type [description]
 * @return {[type]}            [description]
 */
exports.getCopyBuildConf = function (copy_id) {
    return dataApi.carbon.findById(copy_id);
};

/**
 * 获取副本英雄配置
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
exports.getCopyHeroConf = function (copy_id) {
    return dataApi.carbon_hero.findById(copy_id);
};

/**
 * 获取副本的配置
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
exports.getCopyConf = function (copy_id) {
    return _getCopyConf(copy_id);
};

/**
 * 获取副本通关条件
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
exports.getCopyCondition = function (copy_id) {
    var condition_list = [];
    var map_condition_conf = dataApi.map_condition.findById(copy_id);
    if (!map_condition_conf) {
        console.error('map_condition_conf type can not found:' + copy_id);
        return condition_list;
    }
    condition_list.push({
        type: map_condition_conf.first_condition,
        param1: map_condition_conf.first_condition_param1,
        param2: map_condition_conf.first_condition_param2,
        need: 1
    });
    condition_list.push({
        type: map_condition_conf.second_condition,
        param1: map_condition_conf.second_condition_param1,
        param2: map_condition_conf.second_condition_param2,
    });
    condition_list.push({
        type: map_condition_conf.third_condition,
        param1: map_condition_conf.third_condition_param1,
        param2: map_condition_conf.third_condition_param2,
    });
    return condition_list;
};

/**
 * 获取副本配置
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
var _getCopyConf = function (copy_id) {
    var map_id = parseInt(copy_id / 100);
    var carbon_map_all_conf = dataApi.carbon_map.findById(map_id);
    var copy_conf;
    _.some(carbon_map_all_conf, function (carbon_map_conf) {
        if (carbon_map_conf.carbon_id == copy_id) {
            copy_conf = carbon_map_conf;
            return true;
        }
    });
    return copy_conf;
};
